﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HardwareInterface;

namespace login
{
    public partial class LoginCheckForm : Form
    {
        IQueryable ids;
        DBRepository dbr;

        public LoginCheckForm(String name)
        {
            dbr = new DBRepository();
            ids = dbr.finduserid_byname(name);
            InitializeComponent();
        }

        private void buttoncheck_Click(object sender, EventArgs e)
        {
            FingerScanApp ap = new FingerScanApp();
            int init = ap.InitDevice();
            if (init == 0)
            {  }  //连接失败
            else if (init == -1)
            {  }  //打开设备失败
            int size = 0;
            Bitmap bmp = new Bitmap(255, 288);
            byte[] img = new byte[256];
            ap.GetLoginFinger(ref img, ref size, ref bmp);

            foreach(int id in ids){
                List<byte[]> lfinger = dbr.getfinger_byid(id);
                foreach(byte[] finger in lfinger){
                    if(ap.Match(finger, img)){
                        MessageBox.Show("ok");
                    }
                }
            }

            ap.ReleaseDevice();

            MessageBox.Show("fail");
        }
    }
}
